//index.js
//获取应用实例
const http = require("../../models/http.js")

Page({
  data:{
    playlists:"" 
  },
  onLoad: function (options){
    http({
      success:(res) =>{
        // console.log(res);
        let playlists = res.data.playlists;
        // console.log(playlists);
        var arr = [];
        playlists.forEach(item=>{
          var obj = {};
          if(playlists.playCount>=100000000){
            playlists.playCount = Math.floor(playlists.playCount/100000000)+"亿"
          }else if(playlists.playCount>=10000){
            playlists.playCount = Math.floor(playlists.playCount/10000)+"万"
          }
          if(item.name.length>=14){
            item.name = item.name.slice(0,14)+"..."
          }
          obj.name = item.name;
          obj.id = item.id;
          obj.cover  = item.coverImgUrl;
          obj.playCount = item.playCount;
          arr.push(obj)
          // console.log(obj);
        })

        this.setData({
          playlists
        })

      }
    }) 
  },

  handleToggle(event){
    let {id} = event.currentTarget.dataset;
    wx.navigateTo({
      // url: '/pages/detail/detail',
      url: `/pages/music-detail/music-detail?id=${id}`,
      
    });
  }
})
